package com.cafe.pro.controller;

import com.cafe.pro.aop.CryptoResponse;
import com.cafe.pro.entity.User;
import com.cafe.pro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    @CryptoResponse
    public ResponseEntity<User> getUser(@PathVariable Integer id) {
        User user = userService.getUserById(id);
        return ResponseEntity.ok(user);
    }

    @GetMapping
    public List<User> list() {
        return userService.listUsers();
    }

    @PostMapping
    public String add(@RequestBody User user) {
        return userService.addUser(user) ? "Success" : "Failed";
    }
}
